function EbeimService() {
	this.url = "http://127.0.0.1:10001";
	
	this.keyNoBindCheck = function(data,callback){
		var url = this.url + "/rest/noIntercept/key_no_bind/check?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax(data,callback);
	}
	
	this.keyBindCheck = function(data,callback){
		var url = this.url + "/rest/noIntercept/key_bind/check?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax(data,callback);
	}
	
	this.authorizationCodeNoBindCheck = function(data,callback){
		var url = this.url + "/rest/noIntercept/authorization_code_no_bind/check?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax(data,callback);
	}
	
	this.authorizationCodeBindCheck = function(data,callback){
		var url = this.url + "/rest/noIntercept/authorization_code_bind/check?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax(data,callback);
	}
	
	this.getComputerMessage = function(callback){
		var url = this.url + "/rest/noIntercept/computer_message/check?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax({},callback);
	}
	
	this.oncePasswordUpdate = function(data,callback){
		var url = this.url + "/rest/noIntercept/short_message/update_password?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.postAjax(data,callback);
	}
	
	this.getMessageCode = function(data,callback){
		var url = this.url + "/rest/noIntercept/short_message/send?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.getAjax(data,callback);
	}
	
	this.getDownloadProcessBar = function(nids,callback){
		var url = this.url + "/rest/downlaod/process/bar?nids=" + nids+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.deleteDownloadProcessBar = function(nids,callback){
		var url = this.url + "/rest/download/process/bar/delete?nids=" + nids+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.deleteDownloadProcessBarByNid = function(nid,callback){
		var url = this.url + "/rest/download/process/bar/delete/nid?nid=" + nid+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.sendMobileCode = function(callback){
		var url = this.url + "/rest/send/mobilecode?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.getPushMessage = function(callback){
		var url = this.url + "/rest/pushmessage/list?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.getUploadProcessBar = function(dsIds,callback){
		var url = this.url + "/rest/upload/process/bar?dsIds=" + dsIds+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.deleteUploadProcessBar = function(dsIds,callback){
		var url = this.url + "/rest/upload/process/bar/delete?dsIds=" + dsIds+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.backup = function(dsId,dsSecurityRank,dynamicCode,callback){
		var url = this.url + "/rest/backup?dsId=" + dsId+"&dsSecurityRank="+dsSecurityRank+"&dynamicCode="+dynamicCode+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.getDataSources = function(callback) {
		var url = this.url + "/rest/datasources/list?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.getDataSourcesByPage = function(offset,pagesize,dsType,status,name,callback) {
		var url = this.url + "/rest/datasources/list/pages?offset="+offset+"&pagesize="+pagesize+"&dsType="+dsType+"&status="+status+"&name="+name+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.recoveryFile = function(dsId,path,version,dynamicCode,abDir,callback,nid){
		var url = this.url + "/rest/recovery?dsId=" + dsId+"&path="+path+"&version="+version
		+"&dynamicCode="+dynamicCode+"&abDir="+abDir+"&nid="+nid+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.getRecoveryRecords = function(id,offset,pagesize,callback){
		var url = this.url + "/rest/recovery/records?id="+id+"&offset="+offset+"&pagesize="+pagesize+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.deleteRecoveryRecords = function(ids,callback){
		var url = this.url + "/rest/recovery/records/delete?ids="+ids+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.loadTmpl(url,callback);
	}
	
	this.getFileChangeLog = function(dsId,path,version,name,callback){
		var url = this.url + "/rest/filechanglog/list?dsId=" + dsId+"&path="+path+"&version="+version+"&name="+name+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}

	this.getDataSource = function(dsId, callback) {
		var url = this.url + "/rest/datasources/"
		var client = new RestServiceJs(url);
		client.find(dsId, callback);
	}
	
	this.getFileList = function(dsId, version, path, callback) {
		var url = this.url + "/rest/datasources/files?dsId="+dsId+"&version="+version+"&path="+path+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.getLineStorageChart = function(callback){
		var url = this.url + "/rest/line/storage/chart?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.getBackuplogs = function(json,callback){
		var url = this.url + "/rest/backlog/list?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.post(json, callback);
	}
	
	this.addDataSource = function(model, callback) {
		var url = this.url + "/rest/datasources/save?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.post(model, callback);
	}
	
	this.getSystemFiles = function(path, callback) {
		var url = this.url + "/rest/system/files?path="+encodeURIComponent(path)+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.getSystemDirs = function(path, callback) {
		var url = this.url + "/rest/system/dirs?path="+encodeURIComponent(path)+"&timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
	
	this.getUserInfo = function(callback){
		var url = this.url + "/rest/userinfo?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}

	this.login = function(data, callback) {
		var url = this.url + "/rest/login?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.post(data, callback);
	}
	
	this.logout = function(callback){
		var url = this.url + "/rest/logout?timestamp="+new Date().getTime();
		var client = new RestServiceJs(url);
		client.findAll(callback);
	}
}

function getUrlParam(name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r!=null) return unescape(r[2]); return null; //返回参数值
} 

var $offset = 0;
var $currentpage = 1;
var $pagesize = 5;
var $total = 1;
var $totalpage = 1;
$(function(){
	$('#w-page').bind('keyup', function(event) {
        if (event.keyCode == "13") {
            //回车执行查询
            page($(this).val());
        }
    });
});

function dsSecurityRankCheck(code,message){
	if(code=="200" || code==200){
		 alert("操作成功.");
		 $('#myModal').modal("hide");
	 }else if(code=="needKey"){
		 alert("请插入正确的key");
	 }else if(code=="needCode"){
		 $("#myModalLabel").html("请输入动态验证码");
		 $('#myModal').modal("show");
		 return;
	 }else if(code=="codeError"){
		 $("#myModalLabel").html("<font color='red'>动态验证码错误，请重新输入</font>");
		 $("#dynamicCode").val("");
		 $('#myModal').modal("show");
		 return;
	 }else if(code=="needKeyCode"){
		 $("#myModalLabel").html("请插入key并输入动态验证码");
		 $('#myModal').modal("show");
		 return;
	 }else{
		 if(message){
			 alert("操作失败，原因:"+message);
		 }else{
			 alert("操作失败，失败代码:"+code);
		 }
	 }
}
var reSendTime = 60;
function sendCodeToMobile(){
	if(reSendTime > 0){
		$("#sendCodeBtn").html(reSendTime+"秒后重新获取");
		setTimeout("sendCodeToMobile()", 1000);
		reSendTime --;
	}else{
		$("#sendCodeBtn").removeAttr("disabled");
		$("#sendCodeBtn").html("获取验证码");
		reSendTime = 60;
	}
}
function send(){
	var service = new EbeimService();
	$("#sendCodeBtn").attr("disabled","disabled");
	$("#myModalLabel").html("<font color='green'>等待系统向您的预留手机发送验证码...</font>");
	service.sendMobileCode(sendMobileCodeCB);
}
var sendMobileCodeCB = function(data){
	var json = eval("("+data+")");
	if(json.code == "200"){
		$("#myModalLabel").html("<font color='green'>系统已向您的预留手机发送了验证码。请注意查收！</font>");
	}else{
		$("#myModalLabel").html("<font color='green'>抱歉，系统无法向您的手机发送验证码！请查看手机号码是否正确。</font>");
	}
	sendCodeToMobile();
}
